"use strict";
/* Controllers */
app.controller("projectListController", ['$scope', '$location', '$rootScope', '$routeParams', 'projectListService', function ($scope, $location, $rootScope, $routeParams, projectListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};
    //vm.p.appID = $routeParams.appID; //  获取应用模块的名称

    //datetimePicker('datetimepicker','myDate');
    //if($rootScope.ds==null) {
    //    vm.ds = getDateStr(-1);
    //    $rootScope.ds = getDateStr(-1);
    //}else {
    //    vm.ds = $rootScope.ds;
    //}

    //vm.dim = 'week';
    //vm.dims = {};
    //vm.dims.items = [{idx:0,label:'日账单',id:'day'},{idx:1,label:'周账单',id:'week'}];
    //if($rootScope.dim==null) {
    //    vm.dim = vm.dims.items[0];
    //    $rootScope.dim = vm.dim;
    //}else {
    //    vm.dim = vm.dims.items[$rootScope.dim.idx];
    //}
    //$scope.vm.onDimSelected = function(id) {
    //    $scope.initializeController();
    //    $rootScope.dim = $scope.vm.dim;
    //};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.listProject = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var params = {};
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        projectListService.listProject(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.listProject();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('projectListService', ['ajaxService', function (ajaxService) {

    this.listProject = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/project/listProject.do", successFunction, errorFunction);
    };
}]);

function projectIDOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/order/project_add/', value,'" target="_blank">', "<u>修改</u>" , '</a>',
        '<a href="#/star/order/project_report/', value,'" target="_blank">', " <u>报告</u>" , '</a>'
    ].join('');
}

function queueOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/order/yarn_quota_list/', row.clusterName, '/', value,'" target="_blank">', "<u>",value,"</u>" , '</a>'
    ].join('');
}
function dbNameOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/order/hdfs_table_list/', row.clusterName, '/', value,'" target="_blank">', "<u>",value,"</u>" , '</a>'
    ].join('');
}
